package com.zwp.base.ui.compose

import androidx.compose.animation.core.*
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.zwp.base.R

@Composable
fun LoadingView(content:String) {
    val animateTween by rememberInfiniteTransition().animateFloat(
        initialValue = 0f,
        targetValue = 360f,
        animationSpec = infiniteRepeatable(tween(1500,easing = LinearEasing), RepeatMode.Restart)
    )
    Column (modifier = Modifier
        .size(100.dp)
        .background(Color(0x88888888), shape = RoundedCornerShape(10.dp))
        .wrapContentWidth(Alignment.CenterHorizontally)
    ) {
        val degree = Math.toRadians(animateTween.toDouble()).toFloat()
        Box(modifier = Modifier
            .padding(top = 15.dp)
            .fillMaxWidth()
            .wrapContentWidth(Alignment.CenterHorizontally)) {
            Image(
                painter = painterResource(R.drawable.dialog_loading_img),
                contentDescription = null,
                modifier = Modifier
                    .size(35.dp)
                    .rotate(animateTween)
            )
        }
        Box(modifier = Modifier
            .padding(top = 15.dp)
            .fillMaxWidth()
            .wrapContentWidth(Alignment.CenterHorizontally)) {
            Text(
                text = content,
                color = Color.White
            )
        }
    }
}

@Preview(showBackground = true)
@Composable
fun Test() {
    LoadingView("Loading..")
}



